<extend name="Public/base"/>

<block name="body">
    <div class="main-title">
        <h2>新增友情链接</h2>
    </div>
    <form action="{:U()}" method="post" class="form-horizontal">
        <div class="form-item">
            <label class="item-label">公司名称<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="company" id="company" value=""><span id="comp"></span>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">链接名称<span class="check-tips">（链接名为页面显示的名称）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="linkname" id="linkname" value=""><span id="linkna"></span>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">链接<span class="check-tips">（链接名称必须http://开头）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" id="link" name="link" value="http://"><span id="li"></span>
            </div>
        </div>
        <div class="form-item">
            <button class="btn submit-btn " id="submit" type="submit" target-form="form-horizontal">确 定</button>
            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        //导航高亮
        highlight_subnav('{:U('link')}');
    </script>

    <!-- 验证 -->
    <script>

        $(function(){

            var ok1 = false;
            var ok2 = false;
            var ok3 = false;

           

            //公司名称验证
            $('#company').blur(function(){
                var str = $(this).val();
                if (str == 0) {
                    $('#comp').html('*内容不能为空').css('color' , 'red');
                }else{
                    var res = /^[a-zA-Z0-9\u4e00-\u9fa5]+$/;
                    if (!res.test(str)) {
                        $('#comp').html('*公司名称格式不对').css('color' , 'red');
                    }else{
                        $('#comp').html('');
                        ok1 = true;
                    }
                }
            });
            

            // 链接名称验证
            $('#linkname').blur(function(){
                var str = $(this).val();
                if (str == 0) {
                   $('#linkna').html('*内容不能为空').css('color' , 'red');
                }else{
                   $('#linkna').html('');
                   ok2 = true;
                }
            });

            // 链接验证
            $('#link').blur(function(){
                var str = $(this).val();
                if (str == 0) {
                   $('#li').html('*链接不能为空').css('color' , 'red');
                }else{
                    var res = /^(http:\/\/)?(www.)?(\w+\.)+\w{2,4}(\/)?$/;
                    if (!res.test(str)) {
                        $('#li').html('*链接格式不对').css('color' , 'red');
                    }else{
                        $('#li').html('');
                        ok3 = true;
                    }
                }
            });

            $('#submit').click(function(){
                if (ok1 && ok2 && ok3) {
                }else{
                    return false;
                }
            });
            
        });
    </script>
</block>
